
package com.ami.kvm.jviewer.gui;

import com.ami.kvm.jviewer.Debug;
import com.ami.kvm.jviewer.common.oem.IOEMIPMICommandDialog;
import com.ami.kvm.jviewer.common.oem.IOEMManager;
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Component;
import java.awt.Container;
import java.awt.Dimension;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.Insets;
import java.awt.Point;
import java.awt.Rectangle;
import java.awt.Toolkit;
import java.awt.datatransfer.Clipboard;
import java.awt.datatransfer.DataFlavor;
import java.awt.datatransfer.Transferable;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.AdjustmentEvent;
import java.awt.event.AdjustmentListener;
import java.awt.event.KeyAdapter;
import java.awt.event.KeyEvent;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.util.Hashtable;
import javax.swing.AbstractCellEditor;
import javax.swing.JButton;
import javax.swing.JDialog;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JMenuItem;
import javax.swing.JPanel;
import javax.swing.JScrollBar;
import javax.swing.JScrollPane;
import javax.swing.JTable;
import javax.swing.JTextArea;
import javax.swing.border.Border;
import javax.swing.border.CompoundBorder;
import javax.swing.border.EmptyBorder;
import javax.swing.border.MatteBorder;
import javax.swing.border.SoftBevelBorder;
import javax.swing.table.DefaultTableModel;
import javax.swing.table.TableCellEditor;
import javax.swing.table.TableCellRenderer;
import javax.swing.table.TableColumn;
import javax.swing.table.TableColumnModel;
import javax.swing.table.TableModel;

public class IPMICommandDialog extends JDialog implements ActionListener {
	private final int WIDTH = 800;
	private final int HEIGHT = 500;

	private JPanel summaryPanel;
	private JPanel commandPanel;
	private JScrollPane summaryScrollPane;
	private JLabel commandLabel;
	private JTextArea hexCommandArea;
	private JTextArea asciiCommandArea;
	private JButton sendButton;
	private JButton clearButton;
	private JTable summaryTable;
	private DefaultTableModel summaryTableModel;
	private IPMICommandDialogKeyListener dialogKeyListener;
	private IPMICommandDialogMouseListener dialogMouseListener;
	private IPMICommandDialogPopupMenuActionListener popupMenuActionListener;
	protected static int SEQUENCE_LIMIT = 1000;
	private static Hashtable<Integer, String[]> savedSummary = null;
	private static byte sequenceData = 1;
	private static int sequenceNum = 1;
	private String errorStirng = null;
	private boolean scrollToBottom = false;
	private int scrollMax = 0;
	private JVPopupMenu popupMenu = null;
	private Component rightClickComponent = null;

	private JTextArea textAreaCell;

	public IPMICommandDialog(JFrame paramJFrame) {
		super(paramJFrame, LocaleStrings.getString("AG_1_IPMI"), false);
		this.dialogKeyListener = new IPMICommandDialogKeyListener();
		this.dialogMouseListener = new IPMICommandDialogMouseListener();
		this.popupMenuActionListener = new IPMICommandDialogPopupMenuActionListener();
		initDialogPopupMenu();
	}

	public void showDialog() {
		Point localPoint = JViewerApp.getInstance().getPopUpWindowPosition(800, 500);

		setBounds(new Rectangle(localPoint.x, localPoint.y, 800, 500));
		setMinimumSize(new Dimension(800, 500));
		if (this.summaryPanel == null)
			this.summaryPanel = createSummaryPanel();
		getContentPane().add(this.summaryPanel, "Center");
		if (this.commandPanel == null)
			this.commandPanel = createCommandPanel();
		getContentPane().add(this.commandPanel, "South");
		if (savedSummary != null)
			restoreSummary();
		setVisible(true);
		addWindowListener(new IPMICommandDialogWindowListener());
	}

	private JPanel createSummaryPanel() {
		Color localColor = new Color(237, 237, 237);

		Object[][] arrayOfObject = new Object[0][];
		String[] arrayOfString = { LocaleStrings.getString("AG_9_IPMI"), LocaleStrings.getString("AG_10_IPMI") };
		this.summaryTableModel = new DefaultTableModel(arrayOfObject, arrayOfString);
		this.summaryTable = new JTable(this.summaryTableModel) {

			public Component prepareRenderer(TableCellRenderer paramAnonymousTableCellRenderer, int paramAnonymousInt1,
					int paramAnonymousInt2) {

				MatteBorder localMatteBorder = new MatteBorder(0, 0, 2, 0, Color.GRAY);
				EmptyBorder localEmptyBorder = new EmptyBorder(0, 1, 0, 1);
				CompoundBorder localCompoundBorder = new CompoundBorder(localMatteBorder, localEmptyBorder);
				IPMICommandDialog.TextWrapTableCellRenderer localTextWrapTableCellRenderer = (IPMICommandDialog.TextWrapTableCellRenderer) super.prepareRenderer(
						paramAnonymousTableCellRenderer, paramAnonymousInt1, paramAnonymousInt2);
				if (paramAnonymousInt1 % 2 == 0) {
					localTextWrapTableCellRenderer.setBackground(new Color(230, 230, 230));
					localTextWrapTableCellRenderer.setBorder(null);
				} else {
					localTextWrapTableCellRenderer.setBackground(Color.WHITE);
					localTextWrapTableCellRenderer.setBorder(localCompoundBorder);
				}
				return localTextWrapTableCellRenderer;
			}
		};
		this.summaryTable.setShowHorizontalLines(false);
		this.summaryTable.setFocusable(false);
		this.summaryTable.setCellSelectionEnabled(true);
		this.summaryTable.setColumnSelectionAllowed(true);
		this.summaryTable.setRowSelectionAllowed(true);
		this.summaryTable.setSelectionMode(0);
		this.summaryTable.addMouseListener(this.dialogMouseListener);
		setSummaryTableCellRenderer();
		setSummaryTableCellEditor();
		this.summaryScrollPane = new JScrollPane(this.summaryTable, 20, 30);

		this.summaryScrollPane.getVerticalScrollBar().addAdjustmentListener(new DialogAdjustmentListener());

		JPanel localJPanel = new JPanel(new BorderLayout());
		MatteBorder localMatteBorder = new MatteBorder(5, 5, 5, 5, localColor);
		localJPanel.setBorder(localMatteBorder);
		localJPanel.add(this.summaryScrollPane, "Center");
		return localJPanel;
	}

	private void setSummaryTableCellRenderer() {
		TextWrapTableCellRenderer localTextWrapTableCellRenderer = new TextWrapTableCellRenderer();
		for (int i = 0; i < this.summaryTable.getColumnCount(); i++) {
			this.summaryTable.getColumnModel().getColumn(i).setCellRenderer(localTextWrapTableCellRenderer);
		}
	}

	private void setSummaryTableCellEditor() {
		TextCellEditor localTextCellEditor = new TextCellEditor();
		for (int i = 0; i < this.summaryTable.getColumnCount(); i++) {
			this.summaryTable.getColumnModel().getColumn(i).setCellEditor(localTextCellEditor);
		}
	}

	private JPanel createCommandPanel() {
		Color localColor = new Color(237, 237, 237);

		JPanel localJPanel = new JPanel(new BorderLayout(10, 10));
		this.commandLabel = new JLabel(LocaleStrings.getString("AG_2_IPMI"));
		localJPanel.add(this.commandLabel, "North");
		localJPanel.add(createTextPanel(), "Center");
		localJPanel.add(createButtonPanel(), "South");
		MatteBorder localMatteBorder = new MatteBorder(5, 5, 5, 5, localColor);
		localJPanel.setBorder(localMatteBorder);
		return localJPanel;
	}

	private JPanel createTextPanel() {
		JPanel localJPanel = new JPanel(new GridBagLayout());
		GridBagConstraints localGridBagConstraints = new GridBagConstraints();

		localGridBagConstraints.fill = 2;
		localGridBagConstraints.insets = new Insets(1, 1, 1, 1);
		localGridBagConstraints.gridx = 0;
		localGridBagConstraints.gridy = 0;
		localGridBagConstraints.gridwidth = 1;
		localGridBagConstraints.gridheight = 1;
		localGridBagConstraints.weightx = 1.0D;
		localGridBagConstraints.weighty = 1.0D;
		JLabel localJLabel1 = new JLabel(LocaleStrings.getString("AG_9_IPMI"));
		localJLabel1.setHorizontalAlignment(0);
		localJLabel1.setVerticalAlignment(0);
		localJPanel.add(localJLabel1, localGridBagConstraints);

		localGridBagConstraints.insets = new Insets(1, 1, 2, 2);
		localGridBagConstraints.gridy = 1;
		this.hexCommandArea = new JTextArea(2, 25);
		this.hexCommandArea.setAutoscrolls(true);
		this.hexCommandArea.setLineWrap(true);
		this.hexCommandArea.setWrapStyleWord(true);
		this.hexCommandArea.setBorder(new SoftBevelBorder(1));
		this.hexCommandArea.addKeyListener(this.dialogKeyListener);
		this.hexCommandArea.addMouseListener(this.dialogMouseListener);
		JScrollPane localJScrollPane1 = new JScrollPane(this.hexCommandArea, 20, 31);

		localJPanel.add(localJScrollPane1, localGridBagConstraints);

		localGridBagConstraints.insets = new Insets(1, 1, 1, 1);
		localGridBagConstraints.gridx = 1;
		localGridBagConstraints.gridy = 0;
		JLabel localJLabel2 = new JLabel(LocaleStrings.getString("AG_10_IPMI"));
		localJLabel2.setHorizontalAlignment(0);
		localJLabel2.setVerticalAlignment(0);
		localJPanel.add(localJLabel2, localGridBagConstraints);

		localGridBagConstraints.insets = new Insets(1, 2, 2, 1);
		localGridBagConstraints.gridy = 1;
		this.asciiCommandArea = new JTextArea(2, 25);
		this.asciiCommandArea.setRows(2);
		this.asciiCommandArea.setAutoscrolls(true);
		this.asciiCommandArea.setLineWrap(true);
		this.asciiCommandArea.setWrapStyleWord(true);
		this.asciiCommandArea.setBorder(new SoftBevelBorder(1));
		this.asciiCommandArea.addKeyListener(this.dialogKeyListener);
		this.asciiCommandArea.addMouseListener(this.dialogMouseListener);

		JScrollPane localJScrollPane2 = new JScrollPane(this.asciiCommandArea, 20, 31);

		localJPanel.add(localJScrollPane2, localGridBagConstraints);

		return localJPanel;
	}

	private JPanel createButtonPanel() {
		JPanel localJPanel = new JPanel(new GridBagLayout());
		GridBagConstraints localGridBagConstraints = new GridBagConstraints();

		localGridBagConstraints.fill = 2;
		localGridBagConstraints.insets = new Insets(1, 1, 1, 1);
		localGridBagConstraints.gridx = 0;
		localGridBagConstraints.gridy = 0;
		localGridBagConstraints.gridwidth = 1;
		localGridBagConstraints.gridheight = 1;
		localGridBagConstraints.weightx = 1.0D;
		localJPanel.add(new JPanel(), localGridBagConstraints);

		localGridBagConstraints.weightx = 0.0D;
		localGridBagConstraints.gridx = 1;
		localGridBagConstraints.insets = new Insets(1, 1, 1, 1);
		this.sendButton = new JButton(LocaleStrings.getString("AG_3_IPMI"));
		this.sendButton.addActionListener(this);
		this.sendButton.addKeyListener(this.dialogKeyListener);
		localJPanel.add(this.sendButton, localGridBagConstraints);

		localGridBagConstraints.insets = new Insets(1, 5, 1, 1);
		localGridBagConstraints.gridx = 2;
		this.clearButton = new JButton(LocaleStrings.getString("AG_12_IPMI"));
		this.clearButton.addActionListener(this);
		this.clearButton.addKeyListener(this.dialogKeyListener);
		localJPanel.add(this.clearButton, localGridBagConstraints);

		return localJPanel;
	}

	private void sendCommand() {
		String str = this.hexCommandArea.getText();

		if (str.length() > 0) {
			int[] arrayOfInt = formCommandArray(this.hexCommandArea.getText());
			byte[] arrayOfByte = null;
			if (arrayOfInt != null) {
				arrayOfByte = new byte[arrayOfInt.length];
				for (int i = 0; i < arrayOfInt.length; i++) {
					arrayOfByte[i] = ((byte) arrayOfInt[i]);
				}
			}
			if ((arrayOfByte == null) && (this.errorStirng != null)) {
				this.hexCommandArea.setText("");
				this.asciiCommandArea.setText("");
				InfoDialog.showDialog(this, this.errorStirng, LocaleStrings.getString("AG_6_IPMI"), 2);

				this.errorStirng = null;
			} else if (arrayOfByte.length < 2) {
				this.hexCommandArea.setText("");
				this.asciiCommandArea.setText("");
				this.errorStirng = LocaleStrings.getString("AG_11_IPMI");
				InfoDialog.showDialog(this, this.errorStirng, LocaleStrings.getString("AG_6_IPMI"), 2);

				this.errorStirng = null;
			} else {
				JViewerApp.getInstance().onSendIPMICommand(sequenceData, arrayOfByte);
				appendRequestText();
				sequenceData = (byte) ++sequenceNum;
				resetSequence();
			}
		}
	}

	private void resetSequence() {
		int i = JViewerApp.getOEMManager().getOEMIoemipmiCommandDialog().getOEMSEQUENCE_LIMIT();
		if (sequenceData > i) {
			sequenceNum = 1;
			sequenceData = 1;
		}
	}

	private void clearSummary() {
		for (int i = this.summaryTable.getRowCount() - 1; i >= 0; i--)
			this.summaryTableModel.removeRow(i);
		sequenceNum = 1;
		sequenceData = 1;
	}

	public void actionPerformed(ActionEvent paramActionEvent) {
		if (paramActionEvent.getSource().equals(this.sendButton)) {
			sendCommand();
		} else if (paramActionEvent.getSource().equals(this.clearButton)) {
			clearSummary();
		}
	}

	private int[] formCommandArray(String paramString) {
		int[] arrayOfInt = null;
		String str = paramString;
		String[] arrayOfString = null;
		try {
			if (str.contains("0x")) {
				str = str.replaceAll("0x ", "");
				str = str.replaceAll("0x", "");
			} else if (str.startsWith(" ")) {
				str = str.replaceFirst(" ", "");
			} else if (str.contains("\n")) {
				str = str.replaceAll("\n", "");
			}
			arrayOfString = str.split(" ");
			if (arrayOfString.length >= 1) {
				arrayOfInt = new int[arrayOfString.length];
			} else {
				this.hexCommandArea.setText("");
				this.asciiCommandArea.setText("");
				return null;
			}
			for (int i = 0; i < arrayOfString.length; i++) {
				try {
					arrayOfString[i] = arrayOfString[i].trim();
					arrayOfInt[i] = Integer.parseInt(arrayOfString[i], 16);
				} catch (NumberFormatException localNumberFormatException) {
					this.errorStirng = (LocaleStrings.getString("AG_6_IPMI") + " \"" + arrayOfString[i] + "\".\n"
							+ LocaleStrings.getString("AG_7_IPMI") + "\n" + "( " + LocaleStrings.getString("AG_8_IPMI")
							+ "0x2a 0x1f )");

					Debug.out.println("Invalid command");
					Debug.out.println(localNumberFormatException);
					return null;
				}
			}
		} catch (NullPointerException localNullPointerException) {
			this.errorStirng = (LocaleStrings.getString("AG_6_IPMI") + " \"" + paramString + "\".\n"
					+ LocaleStrings.getString("AG_7_IPMI") + "\n" + "( " + LocaleStrings.getString("AG_8_IPMI")
					+ "0x2a 0x1f )");

			Debug.out.println(localNullPointerException);
			return null;
		}
		return arrayOfInt;
	}

	private String convertHexToASCII(String paramString) {
		String str = "";
		int[] arrayOfInt = formCommandArray(paramString);
		if (arrayOfInt == null)
			return null;
		for (int i = 0; i < arrayOfInt.length; i++) {
			if (arrayOfInt[i] < 32) {
				str = str + ".    ";
			} else
				str = str + (char) arrayOfInt[i] + "    ";
			if ((i > 0) && ((i + 1) % 16 == 0))
				str = str + "\n";
		}
		return str;
	}

	public void onIPMICommandRespose(byte paramByte, String paramString) {
		appendResponseText(paramByte, paramString);
	}

	private void appendRequestText() {
		if (this.hexCommandArea.getText().equals(""))
			return;
		int i = 2 * sequenceNum - 2;
		String str = convertHexToASCII(this.hexCommandArea.getText());
		if (str != null) {
			str = "\n" + str;
		} else
			str = "";
		Object[] arrayOfObject = { LocaleStrings.getString("AG_4_IPMI") + " :\n" + this.hexCommandArea.getText(), str };
		this.summaryTableModel.insertRow(i, arrayOfObject);
		this.hexCommandArea.setText("");
		this.asciiCommandArea.setText("");
		this.scrollToBottom = true;
		this.summaryTable.setFocusable(true);
	}

	public void appendResponseText(int paramInt, String paramString) {
		int i = 2 * paramInt - 1;
		String str = convertHexToASCII(paramString);
		if (str != null) {
			str = "\n" + str;
		} else
			str = "";
		Object[] arrayOfObject = { LocaleStrings.getString("AG_5_IPMI") + " :\n" + paramString, str };
		this.summaryTableModel.insertRow(i, arrayOfObject);
		this.scrollToBottom = true;
	}

	private void saveCommandSummary() {
		int i = this.summaryTableModel.getRowCount();
		int j = this.summaryTableModel.getColumnCount();
		String[][] arrayOfString = new String[i][j];
		savedSummary = new Hashtable();
		for (int k = 0; k < i; k++) {
			for (int m = 0; m < j; m++)
				arrayOfString[k][m] = ((String) this.summaryTableModel.getValueAt(k, m));
			savedSummary.put(Integer.valueOf(k), arrayOfString[k]);
		}
	}

	private void restoreSummary() {
		if (this.summaryTableModel != null) {
			int i = savedSummary.size();

			for (int j = 0; j < i; j++) {
				String[] arrayOfString = (String[]) savedSummary.get(Integer.valueOf(j));
				arrayOfString = localizeSummaryData(arrayOfString);
				this.summaryTableModel.addRow(arrayOfString);
			}
		}
		savedSummary = null;
	}

	private String[] localizeSummaryData(String[] paramArrayOfString) {
		if (paramArrayOfString[0].startsWith(LocaleStrings.getPreviousLocaleString("AG_4_IPMI"))) {
			paramArrayOfString[0] = paramArrayOfString[0].replaceAll(LocaleStrings.getPreviousLocaleString("AG_4_IPMI"),
					LocaleStrings.getString("AG_4_IPMI"));

		} else if (paramArrayOfString[0].startsWith(LocaleStrings.getPreviousLocaleString("AG_5_IPMI"))) {
			paramArrayOfString[0] = paramArrayOfString[0].replaceAll(LocaleStrings.getPreviousLocaleString("AG_5_IPMI"),
					LocaleStrings.getString("AG_5_IPMI"));
		}

		if (paramArrayOfString[0].contains(LocaleStrings.getPreviousLocaleString("D_49_JVAPP"))) {
			paramArrayOfString[0] = paramArrayOfString[0].replaceAll(
					LocaleStrings.getPreviousLocaleString("D_49_JVAPP"), LocaleStrings.getString("D_49_JVAPP"));
		}

		return paramArrayOfString;
	}

	public void closeIPMICommandDialog() {
		saveCommandSummary();
		IPMICommandDialog localIPMICommandDialog = null;
		JViewerApp.getInstance().setIPMIDialog(localIPMICommandDialog);
		dispose();
	}

	private void initDialogPopupMenu() {
		if (this.popupMenu == null) {
			this.popupMenu = new JVPopupMenu();
			this.popupMenu.createEditPopup();
			this.popupMenu.addActionListener(this.popupMenuActionListener);
		}
	}

	private class IPMICommandDialogKeyListener extends KeyAdapter {
		private IPMICommandDialogKeyListener() {
		}

		public void keyPressed(KeyEvent paramKeyEvent) {
			if (paramKeyEvent.getKeyCode() == 10)
				if ((paramKeyEvent.getSource().equals(IPMICommandDialog.this.sendButton))
						|| (paramKeyEvent.getSource().equals(IPMICommandDialog.this.hexCommandArea))
						|| (paramKeyEvent.getSource().equals(IPMICommandDialog.this.asciiCommandArea))) {

					IPMICommandDialog.this.sendCommand();
					paramKeyEvent.consume();
				} else if (paramKeyEvent.getSource().equals(IPMICommandDialog.this.clearButton)) {
					IPMICommandDialog.this.clearSummary();
					paramKeyEvent.consume();
				}
		}

		public void keyReleased(KeyEvent paramKeyEvent) {
			String str1 = null;
			String str2 = "";

			if (paramKeyEvent.getSource().equals(IPMICommandDialog.this.asciiCommandArea)) {
				IPMICommandDialog.this.hexCommandArea.setText("");
				str1 = IPMICommandDialog.this.asciiCommandArea.getText();
				str1 = str1.replaceAll(" ", "");
				char[] arrayOfChar = str1.toCharArray();
				for (int i = 0; i < arrayOfChar.length; i++)
					str2 = str2 + Integer.toHexString(arrayOfChar[i]) + " ";
				IPMICommandDialog.this.hexCommandArea.setText(str2);
			} else if (paramKeyEvent.getSource().equals(IPMICommandDialog.this.hexCommandArea)) {
				IPMICommandDialog.this.asciiCommandArea.setText("");
				str1 = IPMICommandDialog.this.convertHexToASCII(IPMICommandDialog.this.hexCommandArea.getText());
				IPMICommandDialog.this.asciiCommandArea.setText(str1);
			}
		}
	}

	private class IPMICommandDialogWindowListener extends WindowAdapter {
		private IPMICommandDialogWindowListener() {
		}

		public void windowClosing(WindowEvent paramWindowEvent) {
			IPMICommandDialog.this.closeIPMICommandDialog();
		}
	}

	private class TextWrapTableCellRenderer extends JTextArea implements TableCellRenderer {
		private TextWrapTableCellRenderer() {
		}

		public Component getTableCellRendererComponent(JTable paramJTable, Object paramObject, boolean paramBoolean1,
				boolean paramBoolean2, int paramInt1, int paramInt2) {
			setText((String) paramObject);
			setLineWrap(true);
			setWrapStyleWord(true);

			setSize(paramJTable.getColumnModel().getColumn(paramInt2).getWidth(), getPreferredSize().height);
			if (paramJTable.getRowHeight(paramInt1) < getPreferredSize().height) {
				paramJTable.setRowHeight(paramInt1, getPreferredSize().height);
			}
			return this;
		}
	}

	private class TextCellEditor extends AbstractCellEditor implements TableCellEditor {
		Border outside = new MatteBorder(0, 0, 2, 0, Color.GRAY);
		Border inside = new EmptyBorder(0, 1, 0, 1);
		Border highlight = new CompoundBorder(this.outside, this.inside);

		public TextCellEditor() {
			IPMICommandDialog.this.textAreaCell = new JTextArea();
		}

		public Component getTableCellEditorComponent(JTable paramJTable, Object paramObject, boolean paramBoolean,
				int paramInt1, int paramInt2) {
			if (paramInt1 % 2 == 0) {
				IPMICommandDialog.this.textAreaCell.setBackground(new Color(230, 230, 230));
				IPMICommandDialog.this.textAreaCell.setBorder(null);
			} else {
				IPMICommandDialog.this.textAreaCell.setBackground(Color.WHITE);
				IPMICommandDialog.this.textAreaCell.setBorder(this.highlight);
			}

			IPMICommandDialog.this.textAreaCell.setLineWrap(true);
			IPMICommandDialog.this.textAreaCell.setText((String) paramObject);
			IPMICommandDialog.this.textAreaCell.setEditable(false);
			IPMICommandDialog.this.textAreaCell.addMouseListener(IPMICommandDialog.this.dialogMouseListener);
			return IPMICommandDialog.this.textAreaCell;
		}

		public Object getCellEditorValue() {
			return IPMICommandDialog.this.textAreaCell.getText();
		}
	}

	private class DialogAdjustmentListener implements AdjustmentListener {
		private DialogAdjustmentListener() {
		}

		public void adjustmentValueChanged(AdjustmentEvent paramAdjustmentEvent) {
			if ((IPMICommandDialog.this.scrollToBottom)
					|| (IPMICommandDialog.this.scrollMax < IPMICommandDialog.this.summaryScrollPane
							.getVerticalScrollBar().getMaximum())) {
				IPMICommandDialog.this.scrollMax = IPMICommandDialog.this.summaryScrollPane.getVerticalScrollBar()
						.getMaximum();
				IPMICommandDialog.this.summaryScrollPane.getVerticalScrollBar()
						.setValue(IPMICommandDialog.this.scrollMax);
				IPMICommandDialog.this.scrollToBottom = false;
			}
		}
	}

	private class IPMICommandDialogMouseListener extends MouseAdapter {
		private IPMICommandDialogMouseListener() {
		}

		public void mouseReleased(MouseEvent paramMouseEvent) {
			Clipboard localClipboard = Toolkit.getDefaultToolkit().getSystemClipboard();
			Transferable localTransferable = localClipboard.getContents(null);
			IPMICommandDialog.this.rightClickComponent = paramMouseEvent.getComponent();
			if (IPMICommandDialog.this.rightClickComponent != null) {
				IPMICommandDialog.this.popupMenu.enableAll();
				if ((IPMICommandDialog.this.rightClickComponent instanceof JTextArea)) {
					JTextArea localJTextArea = (JTextArea) IPMICommandDialog.this.rightClickComponent;
					if (!localJTextArea.isEditable()) {
						IPMICommandDialog.this.popupMenu.getMenuItem("Cut").setEnabled(false);
						IPMICommandDialog.this.popupMenu.getMenuItem("Paste").setEnabled(false);
					}
					if (localJTextArea.getSelectedText() == null) {
						IPMICommandDialog.this.popupMenu.getMenuItem("Cut").setEnabled(false);
						IPMICommandDialog.this.popupMenu.getMenuItem("Copy").setEnabled(false);
					}
					if ((localTransferable.equals(null))
							|| (!localTransferable.isDataFlavorSupported(DataFlavor.stringFlavor))) {
						IPMICommandDialog.this.popupMenu.getMenuItem("Paste").setEnabled(false);
					}
				} else {
					IPMICommandDialog.this.popupMenu.getMenuItem("Copy").setEnabled(false);
					IPMICommandDialog.this.popupMenu.getMenuItem("Cut").setEnabled(false);
					IPMICommandDialog.this.popupMenu.getMenuItem("Paste").setEnabled(false);
				}
				if (isPopupTrigger(paramMouseEvent)) {
					IPMICommandDialog.this.popupMenu.show(IPMICommandDialog.this.rightClickComponent,
							paramMouseEvent.getX(), paramMouseEvent.getY());
				}
			}
		}

		private boolean isPopupTrigger(MouseEvent paramMouseEvent) {
			boolean bool = false;
			if (paramMouseEvent.isPopupTrigger())
				bool = true;
			return bool;
		}
	}

	private class IPMICommandDialogPopupMenuActionListener implements ActionListener {
		private IPMICommandDialogPopupMenuActionListener() {
		}

		public void actionPerformed(ActionEvent paramActionEvent) {
			String str = paramActionEvent.getActionCommand();
			JTextArea localJTextArea;
			if (IPMICommandDialog.this.rightClickComponent.equals(IPMICommandDialog.this.textAreaCell)) {
				localJTextArea = (JTextArea) IPMICommandDialog.this.rightClickComponent;
				if (str.equals("Copy")) {
					localJTextArea.copy();
				}
			} else if ((IPMICommandDialog.this.rightClickComponent.equals(IPMICommandDialog.this.hexCommandArea))
					|| (IPMICommandDialog.this.rightClickComponent.equals(IPMICommandDialog.this.asciiCommandArea))) {
				localJTextArea = (JTextArea) IPMICommandDialog.this.rightClickComponent;
				if (str.equals("Cut")) {
					localJTextArea.cut();
				} else if (str.equals("Copy")) {
					localJTextArea.copy();
				} else if (str.equals("Paste")) {
					localJTextArea.paste();
				}
			}
		}
	}
}

/*
 * Location: D:\Users\tianlin\Downloads\JViewer.jar!\com\ami\kvm\jviewer\gui\
 * IPMICommandDialog.class Java compiler version: 5 (49.0) JD-Core Version:
 * 0.7.1
 */